package com.example.literaturesystem.dao.book;

import com.example.literaturesystem.domain.base.BaseModel;
import com.example.literaturesystem.domain.team.Team;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("chineseBookDao")
public interface IChineseBookDao {
    @Select("<script>SELECT  * FROM booktable2 WHERE 1=1\n" +
            "<if test=\"isbn!=null and isbn!=''\">\n" +
            "AND ISBN=#{isbn}\n" +
            "</if>\n" +
            "<if test=\"publisherID!=null and publisherID!=''\">\n" +
            "AND PublisherID=#{publisherID}\n" +
            "</if>\n" +
            "<if test=\"publisherYear!=null and publisherYear!=''\">\n" +
            "AND PublisherYear=#{publisherYear}\n" +
            "</if>\n" +
            "<if test=\"catalogue!=null and catalogue!=''\">\n" +
            "AND Catalogue=#{catalogue}\n" +
            "</if>\n" +
            "<if test=\"editType!=null and editType!=''\">\n" +
            "AND EditType=#{editType}\n" +
            "</if>\n" +
            "<if test=\"diskPath!=null and diskPath!=''\">\n" +
            " AND DiskPath=#{diskPath}\n" +
            "</if>" +
            "<if test=\"position!=null and position!=''\">\n" +
            "AND Position=#{position}\n" +
            "</if>\n" +
            "<if test=\"firstKeyWord!=null and firstKeyWord!=''\">\n" +
            "AND FirstKeyWord=#{firstKeyWord}\n" +
            "</if>\n" +
            "<if test=\"secondKeyWord!=null and secondKeyWord!=''\">\n" +
            "AND SecondKeyWord=#{secondKeyWord}\n" +
            "</if>\n" +
            "<if test=\"thirdKeyWord!=null and thirdKeyWord!=''\">\n" +
            "AND ThirdKeyWord=#{thirdKeyWord}\n" +
            "</if>\n" +
            "<if test=\"forthKeyWord!=null and forthKeyWord!=''\">\n" +
            "AND ForthKeyWord=#{forthKeyWord}\n" +
            "</if>\n" +
            "<if test=\"note!=null and note!=''\">\n" +
            "AND Note=#{note}\n" +
            "</if>\n" +
            "<if test=\"ifuse!=null and ifuse!=''\">\n" +
            "AND IfUse=#{ifuse}\n" +
            "</if>\n" +
            "<if test=\"dateTime!=null and dateTime!=''\">\n" +
            "AND DateTime=#{dateTime}\n" +
            "</if>\n" +
            "</script>")
    List<Team> query(BaseModel baseModel);

    @Insert("<script>" +
            " INSERT INTO booktable2 (ISBN,PublisherID,PublisherYear, Catalogue,EditType,DiskPath," +
            " Position, FirstKeyWord, SecondKeyWord, ThirdKeyWord, ForthKeyWord, Note, DateTime, IfUse)" +
            " VALUES (#{isbn},#{publisherID},#{publisherYear},#{catalogue},#{editType},#{diskPath}," +
            " #{position},#{firstKeyWord},#{secondKeyWord},#{thirdKeyWord},#{forthKeyWord},#{note},#{dateTime},#{ifuse})" +
            "</script>")
    int insert(BaseModel baseModel);

    @Update("<script>" +
            "UPDATE booktable2\n" +
            " <trim prefix=\"SET\" suffixOverrides=\",\">\n" +
            "<if test=\"userName!=null and userName!=''\">\n" +
            " UserName=#{userName},\n" +
            "</if>\n" +
            "<if test=\"password!=null and password!=''\">\n" +
            " Password=#{password},\n" +
            "</if>\n" +
            "<if test=\"teamName!=null and teamName!=''\">\n" +
            " TeamName=#{teamName},\n" +
            "</if>\n" +
            "<if test=\"category!=null and category!=''\">\n" +
            " Category=#{category},\n" +
            "</if>" +
            "<if test=\"discipline!=null and discipline!=''\">\n" +
            " Discipline=#{discipline},\n" +
            "</if>" +
            "<if test=\"currentNum!=null and currentNum!=''\">\n" +
            " CurrentNum=#{currentNum},\n" +
            "</if>" +
            "<if test=\"maxNum!=null and maxNum!=''\">\n" +
            " MaxNum=#{maxNum},\n" +
            "</if>" +
            "<if test=\"userEmail!=null and userEmail!=''\">\n" +
            " UserEmail=#{userEmail},\n" +
            "</if>" +
            "<if test=\"teamEmail!=null and teamEmail!=''\">\n" +
            " TeamEmail=#{teamEmail},\n" +
            "</if>" +
            "<if test=\"userRole!=null and userRole!=''\">\n" +
            " UserRole=#{userRole},\n" +
            "</if>" +
            "<if test=\"date!=null and date!=''\">\n" +
            " Date=#{date},\n" +
            "</if>" +
            "<if test=\"note!=null and note!=''\">\n" +
            " Note=#{note,}\n" +
            "</if>" +
            "<if test=\"dateTime!=null and dateTime!=''\">\n" +
            " DateTime=#{dateTime},\n" +
            "</if>" +
            "<if test=\"ifuse!=null and ifuse!=''\">\n" +
            " IfUse=#{ifuse}\n" +
            "</if>" +
            " </trim>" +
            "WHERE TeamNo=#{teamNo}" +
            "</script>")
    int update(BaseModel baseModel);
}
